﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Manazra.Helpers;

namespace Manazra.Models.Repository
{
    public class ReplyRepository
    {
        private ManazraDataContext dc = new ManazraDataContext();

        //returns reply by id
        public Reply GetById(int id)
        {
            return dc.Replies.SingleOrDefault(r => r.RecId == id);
        }

        //return reply parent (comment)
        public Comment GetParent(int id)
        {
            return dc.Comments.SingleOrDefault(c => c.RecId == id);
        }

        //deletes a reply
        public void Delete(Reply reply)
        {
            dc.Replies.DeleteOnSubmit(reply);
        }

        //add points to article - for reply
        public void AddPoints(Reply reply)
        {
            reply.Comment.ArticleSegment.Article.Points += (int)RankPoints.Reply;
        }

        //delete points from article - for this reply
        public void DelPoints(Reply reply)
        {
            reply.Comment.ArticleSegment.Article.Points -= (int)RankPoints.Reply;
        }

        //save
        public void Save()
        {
            dc.SubmitChanges();
        }
    }
}
